package longshu.srpc.test.client;

import lombok.extern.slf4j.Slf4j;
import longshu.srpc.SimpleRpcProtocol;
import longshu.srpc.client.RpcClient;
import longshu.srpc.client.RpcConnector;
import longshu.srpc.client.RpcProxy;
import longshu.srpc.client.impl.SimpleRpcClient;
import longshu.srpc.client.impl.SimpleRpcConnector;
import longshu.srpc.client.impl.SimpleRpcProxy;
import longshu.srpc.test.api.HelloService;
import longshu.srpc.test.api.User;
import longshu.srpc.test.api.UserService;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 客户端测试
 *
 * @author LongShu 2017/12/03
 */
@Slf4j
public class RpcConsumer {

    public static void main(String[] args) {
        SimpleRpcProtocol.register();
        RpcConnector rpcConnector = new SimpleRpcConnector(null, "127.0.0.1", 8090);
        RpcProxy rpcProxy = new SimpleRpcProxy(rpcConnector);
        RpcClient rpcClient = new SimpleRpcClient(rpcProxy);

        HelloService helloService = rpcClient.refer(HelloService.class);
        log.info("helloService:{}", helloService);
        String hello = helloService.hello("SimpleRpcClient!");
        log.info(hello);

        Map<String, Object> map = new HashMap<>();
        map.put("name", "客户端");
        map.put("age", 128);
        map.put("os", Arrays.asList("Linux", "Windows", "Mac OS"));

        Map<String, Object> hi = helloService.hi(map);
        log.info("hi: {}", hi);

        UserService userService = rpcClient.refer(UserService.class);
        User user = userService.login("longshu", "123456");
        log.info("user: {}", user);
    }

}
